home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 8.1 KB | 285 lines | [TEXT/MPS ] |
- /*
- * File: Request.cp
- *
- * Contains: xxx put contents here xxx
- *
- * Written by: Rick Violet
- *
- * Copyright: © 1992-1994 by Apple Computer, Inc., all rights reserved.
- *
- * Change History (most recent first):
- *
- * <2> 1/28/94 CMW String utilities have moved to TextUtils.h.
- * 11/18/92 RV xxx put comment here xxx
- *
- * To Do:
- */
-
- #ifndef __Request__
- #include "Request.h"
- #endif
-
- #ifndef __RequestDispatcher__
- #include "RequestDispatcher.h"
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Global Variables
- //—————————————————————————————————————————————————————————————————————————————————————
- extern RequestDispatcher* gTheRequestDispatcher;
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::Request - constructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- Request::Request()
- {
- fWhichService = nil; //———— No Request name yet
- fParamList = nil; //———— create empty list of parameters
- fReturnValue = nil; //———— create empty return value
- fErrorCode = noErr; //———— No errors yet
- fErrorMessage = nil; //———— No error message yet
- fCanceled = false; //———— Not canceled yet
- fRequestIdentifier = 0; //———— No identifier yet
- fSendResetTicks = TickCount(); //———— Set to current Ticks
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::~Request - destructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- Request::~Request()
- {
- //———— dispose of fWhichService
- if( fWhichService != nil )
- {
- delete fWhichService;
- }
-
- //———— dispose of fParamList
- if( fParamList != nil )
- {
- delete fParamList;
- }
-
- //———— dispose of fReturnValue
- if( fReturnValue != nil )
- {
- delete fReturnValue;
- }
-
- //———— dispose of fErrorMessage
- if( fErrorMessage != nil )
- {
- delete fErrorMessage;
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::Initialize - initialize the Request
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::Initialize()
- {
- //———— Tell V.U. not to time out for at least kDefaultTimeOutSeconds
- ResetTimeOutCounter();
-
- return noErr;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::HasBeenCanceled - Check to see if this command has been canceled
- //—————————————————————————————————————————————————————————————————————————————————————
- Boolean
- Request::HasBeenCanceled()
- {
- return fCanceled;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ResetTimeOutCounter - inform V.U. to not let this Request
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::ResetTimeOutCounter( unsigned long pNewTimeOutInterval )
- {
- //———— Set up the Time Manager task to fire again at a later time
- if( !HasBeenCanceled() )
- {
- //———— Keep Track of when we'll time out
- fSendResetTicks = TickCount() + (pNewTimeOutInterval * 60);
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::IsACancelRequest - Is this a Cancel Request?
- // return true if this is a cancel service request
- //—————————————————————————————————————————————————————————————————————————————————————
- Boolean
- Request::IsACancelRequest()
- {
- if( relstring( fWhichService, (char*)kVUAECancelService, false, true ) == 0 )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::IsCancelRequestForThisRequest - is the cancel request
- // passed in as a parameter for canceling this sevice request object
- //—————————————————————————————————————————————————————————————————————————————————————
- Boolean
- Request::IsCancelRequestForThisRequest( Request* pCancelReq )
- {
- long tReqID;
-
- //———— Get the Identifier of the request to cancel
- //———— from the Cancel Request object
- tReqID = pCancelReq->GetIdentifierOfRequesttoCancel();
- if( tReqID == fRequestIdentifier )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetErrorCode - set the Error code for this request
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetErrorCode( OSErr tErr )
- {
- fErrorCode = tErr;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetErrorMessage - set the Error message for this request
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetErrorMessage( char* tErrText )
- {
- //———— Keep Request status in sync with the error code
- fErrorMessage = new char[ strlen( tErrText ) + 1];
- if( fErrorMessage )
- {
- strcpy( fErrorMessage, tErrText );
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::GetNthParam - get the Nth parameter
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::GetNthParam( short pIndex, ScriptValuePtr& pValue, ValueKind& pVKind )
- {
- if( fParamList != nil )
- {
- return fParamList->GetNthItem( pIndex, pValue, pVKind );
- }
- else
- {
- pVKind = kVUAnyKind;
- pValue = nil;
- return errAEWrongParameters;
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::GetParamCount - return the number of parameters
- //—————————————————————————————————————————————————————————————————————————————————————
- short
- Request::GetParamCount()
- {
- if( fParamList != nil )
- {
- return fParamList->GetCount();
- }
- else
- {
- return 0;
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetReturnValue - set the return value for this request
- // to a Number ScriptValue
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetReturnValue( short pNumber )
- {
- ScriptValue* tVal;
-
- tVal = new VUNumber( pNumber );
- fReturnValue = tVal;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetReturnValue - set the return value for this request
- // to a Number ScriptValue
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetReturnValue( long pLongNumber )
- {
- ScriptValue* tVal;
-
- tVal = new VULongNumber( pLongNumber );
- fReturnValue = tVal;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetReturnValue - set the return value for this request
- // to a Boolean ScriptValue
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetReturnValue( Boolean pFlag )
- {
- ScriptValue* tVal;
-
- tVal = new VUBoolean( pFlag );
- fReturnValue = tVal;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetReturnValue - set the return value for this request
- // to a String ScriptValue
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetReturnValue( char* pString )
- {
- ScriptValue* tVal;
-
- tVal = new VUString( pString );
- fReturnValue = tVal;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetReturnValue - set the return value for this request
- // to a String ScriptValue
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetWhichService( char* pServiceText )
- {
- fWhichService = new char[ strlen( pServiceText ) + 1 ];
- if( fWhichService == nil )
- {
- SetErrorCode( memFullErr );
- SetErrorMessage( "Failed to allocate string for Request object." );
- }
- else
- {
- strcpy( fWhichService, pServiceText );
- }
- }
-